package com.eber.demo.design.factory.simple;

interface Car {
    void drive();
}

class BmwCar implements Car {
    @Override
    public void drive() {
        System.out.println("Driving Bmw.");
    }
}

class AudiCar implements Car {
    @Override
    public void drive() {
        System.out.println("Driving Audi.");
    }
}

// 简单工厂类
class CarFactory {
    public static Car getCar(int n) {
        Car car = null;
        switch (n) {
            case 1:
                car = new BmwCar();
                break;
            case 2:
                car = new AudiCar();
                break;
        }
        return car;
    }
}

// ======================================================================

public class FactorySimple {
    public static void main(String[] args) {
        Car car = CarFactory.getCar(1);
        car.drive();
        car = CarFactory.getCar(2);
        car.drive();
    }
}
